<template>
  <el-dialog
    v-model="visible"
    class="component-prod-audit"
    :title="$t('sysManagement.prodAudit')"
    :close-on-click-modal="false"
    width="35%"
  >
    <el-form
      ref="dataFormRef"
      :label-width="$t('language') === 'language' ? '130px' : '80px'"
      @submit.prevent
      @keyup.enter="dataFormSubmit()"
    >
      <el-form-item :label="$t('components.processingStatus')">
        <!-- 1平台进行下线[此处不通过就是下线] 3.审核通过-->
        <el-radio-group v-model="dataForm.status">
          <el-radio :label="3">
            {{ $t('productComm.pass') }}
          </el-radio>
          <el-radio :label="1">
            {{ $t('productComm.noPass') }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item
        v-if="dataForm.status === 1"
        :label="$t('components.denialReason')"
        prop="refuseReason"
      >
        <el-input
          v-model="dataForm.offlineReason"
          type="textarea"
          :autosize="{ minRows: 4, maxRows: 10}"
          maxlength="200"
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <span
        class="dialog-footer"
      >
        <div
          class="default-btn"
          @click="visible = false"
        >{{ $t('remindPop.cancel') }}</div>
        <div
          :class="['default-btn primary-btn']"
          @click="dataFormSubmit()"
        >{{ $t('group.confirmReview') }}</div>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
import { ElMessage, ElMessageBox } from 'element-plus'
import { reactive } from 'vue'

const emit = defineEmits(['refreshDataList'])
const props = defineProps({
  updateUrl: {
    default: '',
    type: String
  }
})

const visible = ref(false)
const dataForm = reactive({
  handleId: null,
  status: 3
})
let prodId = 0
const init = (id) => {
  prodId = id
  visible.value = true
  dataForm.status = 3
  dataForm.offlineReason = ''
}

// 表单提交
const dataFormSubmit = () => {
  if (dataForm.status === 1) {
    const reg = /^\s+$/g
    if (reg.test(dataForm.offlineReason)) {
      ElMessage.warning($t('shopProcess.inputAllSpace'))
      return
    }
  }
  ElMessageBox.confirm($t('components.tipOfflineAuditTip2'), $t('remindPop.remind'), {
    confirmButtonText: $t('remindPop.confirm'),
    cancelButtonText: $t('remindPop.cancel')
  }).then(() => {
    visible.value = false
    http({
      url: http.adornUrl(props.updateUrl),
      method: 'post',
      data: http.adornData({
        handleId: prodId,
        status: dataForm.status,
        offlineReason: dataForm.offlineReason || null
      })
    }).then(() => {
      ElMessage({
        message: $t('remindPop.success'),
        type: 'success',
        duration: 1500,
        onClose: () => {
          visible.value = false
          emit('refreshDataList')
        }
      })
    })
  })
}

defineExpose({
  init
})

</script>

<style lang="scss" scoped>

</style>
